function [ output_args ] = compress(chunk_size)

[folder_path] = uigetdir('../stats', 'Load Wrist Stats Data');
sub_folder = dir(folder_path);

count_folder = 0;
for p = 3 : length(sub_folder)
    file_name = dir(fullfile(folder_path, sub_folder(p).name, '*.csv'));
    file_path = fullfile(folder_path, sub_folder(p).name);
    
    count_file = 0;
    for i = 1 : length(file_name)
        count_file = count_file + 1;
        wrist_data =  csvread(fullfile(file_path, file_name(i).name));
        data_collection(1:size(wrist_data,1), 1:size(wrist_data,2), count_file) = wrist_data;
    end

    count_folder = count_folder + 1;
    mean_by_trials(1:size(data_collection,1), 1:size(data_collection,2), count_folder) = mean(data_collection, 3);
end

count = 0;
result = zeros(ceil(size(mean_by_trials,1) * 2 / chunk_size), size(mean_by_trials,2), size(mean_by_trials,3));
for i = 1 : chunk_size/2: size(data_collection,1)
    count = count + 1;
    
    if(i + chunk_size > size(data_collection,1))
        current_chunk = mean_by_trials(i:end, :, :);
    else
        current_chunk = mean_by_trials(i:i+chunk_size, :, :);
    end
    
    result(count, 1:size(mean_by_trials,2), 1:size(mean_by_trials,3)) = mean(current_chunk, 1);
end
    
file_path = fullfile(file_path, '../..', 'average');
if ~exist(file_path, 'dir')
    mkdir(file_path);
end

onefile = zeros(size(result, 3), size(result, 1) * size(result, 2));
for k = 1:size(result, 3)
    tmp = result(:,:,k);
    tmp = reshape(tmp',1,[]);
    onefile(k, :) = tmp;
end

csvwrite(fullfile(file_path, 'average.csv'), onefile);
end